/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Controllers;

/**
 *
 * @author ozgencetinkaya
 */

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import javax.servlet.ServletException;
import java.io.*;
import java.util.*;
import DAO.UserDAO;
import model.UserBean;

@Controller
@RequestMapping("/editaccount.htm")
public class EditAccountController {
    
    @RequestMapping( method = RequestMethod.GET)
    public String showPage(Map model,HttpServletRequest request,HttpServletResponse response) throws IOException {
        Enumeration enames;
        HttpSession session = request.getSession(true);
        enames = session.getAttributeNames();

        
        if (!enames.hasMoreElements()) {
            response.sendRedirect("signin.htm");
        }
        else{
            UserBean currentUser = (UserBean)(session.getAttribute("currentSessionUser"));
            if(currentUser.isValid())  {
                
                
                model.put("firstname",currentUser.getFirstName());
                model.put("lastname",currentUser.getLastName());
                model.put("email",currentUser.getUsername());
                
                
                return "editaccount";
            }
            else
                response.sendRedirect("signin.htm");
        }
        return "editaccount";
    }
}
